<template>
  <div class="renthouse">
    <header>
      <div class="top">
        <van-icon name="arrow-left" @click="getback" />
        <h3>新房</h3>
        <span></span>
      </div>
    </header>
    <main>
      <div class="three">
        <span>北京</span>
        <!-- 搜索 -->
        <div class="combination">
          <input type="text" placeholder="请在这里输入区域/商圈" />
          <span>
            <van-icon name="search" />
          </span>
        </div>
        <span>地图找房</span>
      </div>
      <div class="selects">
        <dl>
          <dt>
            <i class="iconfont icon-shangpu"></i>
          </dt>
          <dd>找商铺</dd>
        </dl>
        <dl>
          <dt>
            <i class="iconfont icon-xiezilou"></i>
          </dt>
          <dd>找写字楼</dd>
        </dl>
        <dl>
          <dt>
            <i class="iconfont icon-xiaoqu"></i>
          </dt>
          <dd>找小区</dd>
        </dl>
      </div>
      <div class="pulldown">
        <van-dropdown-menu>
          <van-dropdown-item title="区域">
            <van-picker
              :title="标题"
              :columns="abc.columns1"
              @change="onChange"
              :columns-field-names="customFieldName"
            />
          </van-dropdown-item>
          <van-dropdown-item title="价格">
            <van-picker
              :columns="columns2"
              value-key="price"
              confirm-button-text=" "
              cancel-button-text=" "
              getColumnValue="columnIndex"
            />
            <p class="p3">
              <button class="ok2" @click="yes1(getColumnValue)">确定</button>
            </p>
          </van-dropdown-item>
          <van-dropdown-item title="户型" class="hx">
            <!-- <van-picker title="户型" :columns="columns3" > -->
            <p class="maifang">买房选型</p>
            <div class="state">
              <button v-for="(v, i) in columns3" :key="i">{{ v.state }}</button>
            </div>
            <p class="huxing">户型</p>
            <div class="type">
              <button v-for="(v, i) in columns4" :key="i">{{ v.type }}</button>
            </div>
            <p class="p2">
              <button class="ok1">确定</button>
            </p>
            <!-- </van-picker> -->
          </van-dropdown-item>
          <van-dropdown-item title="筛选">
            <p class="chaoxiang">朝向</p>
            <div class="direction">
              <button v-for="(v, i) in columns5" :key="i">
                {{ v.direction }}
              </button>
            </div>
            <p class="p1">
              <button class="empty">清空</button>
              <button class="ok">确定</button>
            </p>
          </van-dropdown-item>
        </van-dropdown-menu>
        <van-cell @click="showPopup">
          <van-icon name="sort" />
        </van-cell>
        <van-popup
          v-model:show="show"
          position="bottom"
          :style="{ height: '40%' }"
        >
          <van-picker title="筛选" :columns="columns5" />
        </van-popup>
      </div>
      <div class="box" v-for="(v, i) in newdata" :key="i">
        <dl>
          <dt>
            <img :src="v.img" alt />
          </dt>
          <dd>
            <p class="bt">{{ v.countrysx }}</p>
            <p>
              <span>{{ v.roomeType }}</span>
              <span>{{ v.title }}</span>
            </p>
            <p class="wan">{{ v.roomeArea }}万</p>
            <button>小区</button>
          </dd>
        </dl>
      </div>
    </main>
    <div class="box1"></div>
  </div>
</template>

<script>
import axios from "axios";
import { ref, reactive } from "vue";
export default {
  setup() {
    let newdata = ref([]);
    const value1 = ref("等等");
    const value2 = ref("a");
    const show = ref(false);

    const showPopup = () => {
      show.value = true;
    };
    let abc = reactive({
      columns1: [],
    });
    const columns2 = ref([]);
    const columns3 = [];
    const columns4 = [];
    const columns5 = [];
    let provinceid = "";
    let customFieldName = {
      text: "province",
      children: "cities",
    };
    const onChange = (value) => {
      // console.log(value.provinceid);
      // console.log(value);
      axios
        .post("/home/cities", {
          provinceid: value.provinceid, //省id
        })
        .then((res) => {
          // console.log(res.data);
          abc.columns1 = res.data.data.children;
          console.log(abc.columns1);
          customFieldName = {
            text: "city",
            children: "children",
          };
        });
    };
    return {
      newdata,
      value1,
      value2,
      abc,
      columns2,
      columns3,
      customFieldName,
      columns4,
      columns5,
      show,
      showPopup,
      onChange,
      provinceid,
    };
  },
  created() {
    axios.get("/home/oldHouse").then((res) => {
      // console.log(res);
      this.newdata = res.data.data;
    });
    axios.get("/home/select").then((res) => {
      // console.log(res);
      this.columns2 = res.data.body.priceList;
      this.columns3 = res.data.body.buyList;
      this.columns4 = res.data.body.roomTypeList;
      this.columns5 = res.data.body.direction;
    });
    //省
    axios.get("/home/proviced").then((res) => {
      // console.log(res);
      this.abc.columns1 = res.data.data;
      console.log(this.abc.columns1);
    });
    // 市
  },
  methods: {
    // 返回首页
    getback() {
      history.back(-1);
    },
    area() {
      console.log(111);
    },
    yes1(getColumnValue) {
      console.log(111);
      console.log(getColumnValue);
    },
  },
};
</script>

<style lang="scss" scoped>
.renthouse {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
header {
  width: 100%;
  height: 60px;
  // top: 0;
  .top {
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    background: #0272f0;
    color: #fff;
    i {
      font-size: 20px;
    }
  }
}
main {
  width: 100%;
  flex: 1;
  overflow-y: scroll;

  .three {
    width: 100%;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    position: sticky;
    top: 0;
    background: white;
    .combination {
      width: 260px;
      height: 30px;
      border: 1px solid #ccc;
      display: flex;
      background: #f4f4f4;
      input {
        width: 222px;
        height: 30px;
        border: none;
        background: #f4f4f4;
        padding-left: 20px;
      }
      span {
        display: block;
        width: 36px;
        height: 30px;
        display: flex;
        align-items: center;
        justify-content: center;
        i {
          font-weight: bolder;
        }
      }
    }
  }
  .selects {
    width: 100%;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: space-around;
    dl {
      dt {
        i {
          font-size: 30px;
          text-align: center;
          display: block;
          color: #fb6408;
        }
      }
    }
  }
  .pulldown {
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
    position: sticky;
    top: 60px;
    background: white;
    .van-dropdown-menu {
      flex: 1;
    }
    .van-cell {
      width: 50px;
    }
  }
  .box {
    width: 100%;
    height: 160px;
    display: flex;
    align-items: center;
    dl {
      width: 100%;
      height: 160px;
      display: flex;
      align-items: center;
      dt {
        width: 140px;
        padding-left: 20px;
        img {
          width: 140px;
          height: 120px;
        }
      }
      dd {
        padding-left: 15px;
        .bt {
          font-weight: bolder;
        }
        .wan {
          color: #ffa217;
          font-weight: bolder;
          font-size: 15px;
        }
        button {
          border: none;
          width: 60px;
          height: 30px;
        }
      }
    }
  }
  .hx {
    .maifang {
      padding-top: 25px;
      padding-left: 42%;
      font-size: 20px;
      font-weight: bolder;
      color: #ccc;
    }
    .state {
      display: flex;
      align-items: center;
      justify-content: space-around;
      width: 100%;
      height: 80px;
      button {
        width: 70px;
        height: 40px;
        border: none;
        background: #fbf7f8;
        color: #999999;
        font-weight: bolder;
      }
    }
  }
  .huxing {
    padding-top: 15px;
    padding-left: 45%;
    font-size: 20px;
    font-weight: bolder;
    color: #ccc;
  }
  .type {
    display: flex;
    // align-items: center;
    // justify-content: space-around;
    width: 100%;
    height: 120px;
    flex-wrap: wrap;
    button {
      width: 70px;
      height: 40px;
      margin-left: 25px;
      border: none;
      background: #fbf7f8;
      color: #999999;
      font-weight: bolder;
      margin-top: 10px;
    }
  }
  .chaoxiang {
    padding-top: 15px;
    padding-left: 45%;
    font-size: 20px;
    font-weight: bolder;
    color: #ccc;
  }
  .direction {
    display: flex;
    flex-wrap: wrap;
    // justify-content: space-around;
    width: 100%;
    height: 140px;
    button {
      margin-top: 20px;
      margin-left: 25px;
      width: 70px;
      height: 40px;
      border: none;
      background: #fbf7f8;
      color: #999999;
      font-weight: bolder;
    }
  }
  .p1 {
    width: 100%;
    height: 40px;
    border-top: 1px solid #ccc;
    button {
      width: 50%;
      height: 40px;
      border: none;
    }
    // 清空
    .empty {
      background: #fff;
    }
    // 筛选确定
    .ok {
      background: #fd5958;
      color: #fff;
    }
  }
  .p2 {
    width: 100%;
    height: 40px;
    border-top: 1px solid #ccc;
    button {
      width: 100%;
      height: 40px;
      border: none;
    }
    // 户型确定
    .ok1 {
      background: #fd5958;
      color: #fff;
    }
  }
  .p3 {
    width: 100%;
    height: 40px;
    border-top: 1px solid #ccc;
    button {
      width: 100%;
      height: 40px;
      border: none;
    }
    // 户型确定
    .ok2 {
      background: #fd5958;
      color: #fff;
    }
  }
}
</style>